home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Lines Curves and Area Fills / PieChart / PieChart.cs next >
Encoding:
Text File  |  2001-01-15  |  1.3 KB  |  44 lines

  1. //---------------------------------------
  2. // PieChart.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class PieChart: PrintableForm
  9. {
  10.      int[] aiValues = { 50, 100, 25, 150, 100, 75 };
  11.  
  12.      public new static void Main()
  13.      {
  14.           Application.Run(new PieChart());
  15.      }
  16.      public PieChart()
  17.      {
  18.           Text = "Pie Chart";
  19.      }
  20.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  21.      {
  22.           Rectangle rect   = new Rectangle(50, 50, 200, 200);
  23.           Pen       pen    = new Pen(clr);
  24.           int       iTotal = 0;
  25.           float     fAngle = 0, fSweep;
  26.  
  27.           foreach(int iValue in aiValues)
  28.                iTotal += iValue;
  29.  
  30.           foreach(int iValue in aiValues)
  31.           {
  32.                fSweep = 360f * iValue / iTotal;
  33.                DrawPieSlice(grfx, pen, rect, fAngle, fSweep);
  34.                fAngle += fSweep;
  35.           }
  36.      }
  37.      protected virtual void DrawPieSlice(Graphics grfx, Pen pen, 
  38.                                          Rectangle rect,
  39.                                          float fAngle, float fSweep)
  40.      {
  41.           grfx.DrawPie(pen, rect, fAngle, fSweep); 
  42.      }
  43. }
  44.